from fastapi import APIRouter, Depends, HTTPException
from typing import Dict

from app.services.info_service import InfoService
from app.models.info import BasicInfoResponse, ParametersResponse, MetaResponse
from app.core.logger import logger

router = APIRouter(tags=["应用信息"])

# 依赖项：创建InfoService实例
def get_info_service():
    return InfoService()

@router.get("/info", response_model=BasicInfoResponse)
async def get_info(
    info_service: InfoService = Depends(get_info_service)
):
    """
    获取应用基本信息
    
    用于获取应用的基本信息
    """
    logger.debug("获取应用基本信息")
    
    try:
        response = await info_service.get_basic_info()
        return response
    except Exception as e:
        logger.error(f"获取应用基本信息失败: {str(e)}")
        raise HTTPException(status_code=500, detail=f"获取应用基本信息失败: {str(e)}")

@router.get("/parameters", response_model=ParametersResponse)
async def get_parameters(
    info_service: InfoService = Depends(get_info_service)
):
    """
    获取应用参数
    
    用于进入页面一开始，获取功能开关、输入参数名称、类型及默认值等使用
    """
    logger.debug("获取应用参数")
    
    try:
        response = await info_service.get_parameters()
        return response
    except Exception as e:
        logger.error(f"获取应用参数失败: {str(e)}")
        raise HTTPException(status_code=500, detail=f"获取应用参数失败: {str(e)}")

@router.get("/meta", response_model=MetaResponse)
async def get_meta(
    info_service: InfoService = Depends(get_info_service)
):
    """
    获取应用Meta信息
    
    用于获取工具icon
    """
    logger.debug("获取应用Meta信息")
    
    try:
        response = await info_service.get_meta()
        return response
    except Exception as e:
        logger.error(f"获取应用Meta信息失败: {str(e)}")
        raise HTTPException(status_code=500, detail=f"获取应用Meta信息失败: {str(e)}")
